package com.deng.etl.common;

import java.sql.Connection;
import java.util.Date;

import com.deng.etl.vo.EtlDailyVo;
import com.deng.util.DateTools;

public class EtlThread extends Thread {

	private EtlDailyVo vo;
	private Date fromDate;
	private Date toDate;
	private int type;//1 insert 2 update 3 delete
	public EtlThread(EtlDailyVo vo,Date fromDate,Date toDate,int type){
		this.vo = vo;
		this.fromDate = fromDate;
		this.toDate = toDate;
		this.type = type;
	}
	@Override
	public void run() {
		try{
			EtlAuto ea = new EtlAuto();
			Connection sourceConn = ea.getSourceConn();
			Connection targetConn = ea.getTargetConn();
			
			if(type == 1){
				ServicesFactory.getEtlImpl(vo.class_name).insertData(sourceConn, targetConn, vo.item_name,
						DateTools.dtsJustDate(fromDate), DateTools.dtsJustDate(toDate));//.insertData(sourceConn, targetConn, DateTools.dtsWithHourT0(stat_time), getToday0());
				
			}else if(type == 2){
				ServicesFactory.getEtlImpl(vo.class_name).updateData(sourceConn, targetConn, vo.item_name,
						DateTools.dtsJustDate(fromDate), DateTools.dtsJustDate(toDate));//.insertData(sourceConn, targetConn, DateTools.dtsWithHourT0(stat_time), getToday0());
			}else{
				ServicesFactory.getEtlImpl(vo.class_name).deleteData(sourceConn, targetConn, vo.item_name,
						DateTools.dtsJustDate(fromDate), DateTools.dtsJustDate(toDate));//.insertData(sourceConn, targetConn, DateTools.dtsWithHourT0(stat_time), getToday0());
			}
			targetConn.close();
			targetConn.close();
		}catch(Exception ex){
			ex.printStackTrace();
		}
		// TODO Auto-generated method stub
		
	}

	
}
